package array;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class search {
    public static int search(int[] nums, int target) {
        int start = 0, end = nums.length - 1;
        while (start <= end){
            int middle = (start+end)/2;
            if(nums[middle] > target){
                end = middle-1;
            } else if (nums[middle] < target){
                start = middle+1;
            } else if (nums[middle] == target){
                return middle;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] a = new int[]{-1,0,3,5,9,12};
        System.out.println(search(a, 9));
    }
}
